package it.univaq.mancoosi.injectors.systemconfiguration.managers;

import it.univaq.mancoosi.injectors.systemconfiguration.managers.ubuntu.UbuntuEnvironmentManager;
import it.univaq.mancoosi.mancoosimm.Boot;
import it.univaq.mancoosi.mancoosimm.BootScript;
import it.univaq.mancoosi.mancoosimm.Configuration;
import it.univaq.mancoosi.mancoosimm.MancoosiFactory;
import it.univaq.mancoosi.mancoosimm.Rule;
import it.univaq.mancoosi.mancoosimm.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;

public abstract class BootManager {
	   protected static  BootManager INSTANCE ;	 
	   protected MancoosiFactory factory; 
	   private Boot boot;
	   protected HashMap<String, Service> serviceMap;
	   
	   // Private constructor prevents instantiation from other classes
	   protected BootManager() {
		   factory = MancoosiFactory.eINSTANCE; 
		   boot = factory.createBoot();
		   this.serviceMap = new HashMap<String, Service>();
	   }
	 
	   public static BootManager getInstance() {
	      return INSTANCE;
	   }
	   
	   public Boot getBoot() {  
		   return boot;
	   }
	   
	   public abstract void createServicesFromSystem();
	   
	   public abstract void synchronize() throws IOException;
	   
	   public abstract Boolean exists(String serviceName);
	   
	   public void syncMap () {
			Iterator<Service> iterator  = null;
			if(UbuntuEnvironmentManager.getInstance().getEnvironment().getBoot() != null){
				iterator = UbuntuEnvironmentManager.getInstance().getEnvironment().getBoot().getServices().iterator();
			}
			if(iterator != null){
				while (iterator.hasNext()) {
					Service curr = iterator.next();
					this.serviceMap.put(curr.getName(), curr);
				}
			}
		}

}
